package mySessions

import (
	"github.com/kataras/iris"
	"github.com/kataras/iris/sessions"
)

var (
	cookieNameForSessionID = "mycookiesessionnameid"
	sess                   = sessions.New(sessions.Config{
		Cookie:       cookieNameForSessionID,
		AllowReclaim: true})
	Administrators = "Administrators"
	sessUser       = sessions.New(sessions.Config{
		Cookie:  Administrators,
		Expires: -1,
	})
)

func Secret(ctx iris.Context) int {
	if auth, _ := sessUser.Start(ctx).GetBoolean("authenticated"); !auth {

		return 403
	}
	return 200
}

func Login(ctx iris.Context) string {

	session := sessUser.Start(ctx)

	//把验证状态保存为true
	session.Set("authenticated", true)
	return session.ID()
}

func Passer(ctx iris.Context) string {
	session := sess.Start(ctx)
	return session.ID()
}
func Logout(ctx iris.Context) {
	session := sessUser.Start(ctx)
	//撤销用户身份验证
	session.Set("authenticated", false)
}
